package jsonrpc

import (
	"github.com/garyburd/redigo/redis"
	"log"
	"my-crawler/concurrence/model"
	"my-crawler/pkh"
)

type ItemSaverService struct {
	Client   *redis.Pool
	RedisKey string
}

func (s *ItemSaverService) Save(item model.SaveItem, result *string) error {
	pool := s.Client.Get()
	_, err := pool.Do("SAdd", s.RedisKey, item.Name)
	common.Check(err)
	log.Printf("jsonRpc:ItemSaverService—— Item %v saved.", item)
	if err == nil {
		*result = "ok"
	} else {
		log.Printf("Error saving item %v: %v",
			item, err)
	}
	return err
}
